<<<<<<< HEAD
import React, {Component} from "react";

export default class Compare extends Component{
    constructor(){
        super();
        this.state={
            supportNum:0,
            objectNum:0,
        }
        
    }
    support=()=>{
        this.setState({supportNum:this.state.supportNum+1,})
    }
    object=()=>{
        this.setState({objectNum:this.state.objectNum+1})
    }
    
    render(){
        console.log(this);// 返回Compare对象实例
        
        const {supportNum,objectNum}=this.state
        let percent=supportNum/(supportNum+objectNum);
        if(isNaN(percent)){
            percent=0;
        }else{
            percent=percent*100;
        }
        return(
            <div>
                <h2>{this.props.title}</h2>
                <p>支持人数：{supportNum}</p>
                <p>反对人数：{objectNum}</p>
                <p>支持率：{percent}%</p>
                <div>
                    <button onClick={this.support}>支持</button>
                    <button onClick={this.object}>反对</button>
                </div>
            </div>
        )
    }
=======
import React, {Component} from "react";

export default class Compare extends Component{
    constructor(){
        super();
        this.state={
            supportNum:0,
            objectNum:0,
        }
        
    }
    support=()=>{
        this.setState({supportNum:this.state.supportNum+1,})
    }
    object=()=>{
        this.setState({objectNum:this.state.objectNum+1})
    }
    
    render(){
        console.log(this);// 返回Compare对象实例
        
        const {supportNum,objectNum}=this.state
        let percent=supportNum/(supportNum+objectNum);
        if(isNaN(percent)){
            percent=0;
        }else{
            percent=percent*100;
        }
        return(
            <div>
                <h2>{this.props.title}</h2>
                <p>支持人数：{supportNum}</p>
                <p>反对人数：{objectNum}</p>
                <p>支持率：{percent}%</p>
                <div>
                    <button onClick={this.support}>支持</button>
                    <button onClick={this.object}>反对</button>
                </div>
            </div>
        )
    }
>>>>>>> 967875b1ab7041f3b69a21650d5b693c6f4b0327
}